package com.AFH.test;

import android.graphics.Canvas;

class Monster extends Sprite {
	private int health;
	private int attack;
	private int attackSpeed;
	private float attackRange;
	AttackThread at = null;
	private int attribute;
	private int level = 0;
	private boolean moneyPlused;

	public Monster(int xPos, int yPos, int attribute) {

		super(xPos, yPos);
		switch (attribute) {
		case 4:
			health = 500;
			speed = 2.4f;
			attack = 20;
			attackSpeed = 500;
			attackRange = 50;
			break;
		case 5:
			health = 300;
			speed = 4.0f;
			attack = 25;
			attackSpeed = 500;
			attackRange = 50;
			break;
		case 6:
			health = 5000;
			speed = 1.0f;
			attack = 150;
			attackSpeed = 1000;
			attackRange = 50;
			break;

		}
		currentSegment = 0;
		this.attribute = attribute;
		// TODO Auto-generated constructor stub
		// at=new AttackThread(this);
	}

	@Override
	public void drawself(Canvas canvas) {
		// TODO Auto-generated method stub
		if (health == 0 && currentSegment != 3) {
			setCurrentSegment(3);
			if (!moneyPlused) {
				GameData.gameProfile.Money += attribute * 10 + level * 5;
				if (attribute == 6)
					GameData.gameProfile.Money += 50;
				moneyPlused = true;
			}
			if (health ==0 ){
				at.art.flag = false;
				at.art.spStart = false;
				at = null;
			}
		}
		
		int ImgIndex1 = animationList.get(currentSegment)[currentFrame];
		BitmapManager.DrawMonster(ImgIndex1, canvas, xPos, yPos, null);

	}

	public void underattack(int att) {
		if (health - att >= 0)
			health = health - att;
		else
			health = 0;
	}

	public void retardment(float retardspeed) {
		speed = speed - retardspeed;
		if (speed <= 0)
			speed = 0.1f;
	}

	public boolean isdead() {
		if (health == 0) {
			// setCurrentSegment(3);

			return true;
		} else
			return false;
	}

	public boolean atStarted() {
		return !(at == null);
	}

	public void attack(Object o, int ani[][]) {
		if (at == null || o != at.ob) {
			if (at != null) {
				at.art.flag = false;
				at.art.spStart = false;
			}
			at = new AttackThread(this);
			at.startAttack(attackSpeed, attack, o);
			at.makeAnimation(ani);
			setCurrentSegment(1);
			// at.startAnimation();
			at.startAnimation();
		}

	}

	public void kill() {
		health = 0;
	}

	public int getAttribute() {
		return attribute;
	}

	public void setAttribute(int attribute) {
		this.attribute = attribute;
	}

	public boolean inAttackRange(float rg) {
		if (rg <= attackRange)
			return true;
		else
			return false;
	}

	public void slow(int slowlevel) {
		speed = speed - slowlevel * 100;
		attackSpeed = attackSpeed + slowlevel * 200;
	}

	public void levelUp(int level) {
		health = health + 50 * level;
		attack = attack + level;
	}

}